#include "openmove_Prefix.h"
#include "SceneBase.h"
#include "OgreEngine.h"
#include "ExampleFrameListener.h"
#include "SkeletalAnimationFrameListener.h"
#include "OgreExternalTextureSourceManager.h"
#include "OgreExternalTextureSource.h"
#include "SceneEcriture.h"

CSceneEcriture :: CSceneEcriture(COgreEngine &Creator, const String & Name, const int pos) : CSceneBase(Creator, Name, pos)
{
}

CSceneEcriture :: ~CSceneEcriture(void)
{
}

void CSceneEcriture :: Create(TCreatorEntities const &CreatorEntities, TCreatorNodes const &CreatorNodes, TCreatorLights const &CreatorLights, ENetConfig IsClient, Vector3 &CameraStartPos)
{
	CSceneBase::Create(CreatorEntities, CreatorNodes, CreatorLights, IsClient, CameraStartPos);

	Entity *ent = findEntity(String("ecriture_bones"));

	TCreatorEntities loupEnt;
	TCreatorNodes loupNode;
	int index = 1;
	if (NULL != ent && ent->hasSkeleton())
	{
		Bone *root = ent->getSkeleton()->getBone(0);
		Node::ChildNodeIterator it = root->getChildIterator();
		while (it.hasMoreElements())
		{			
			Bone *child = static_cast<Bone *>(it.getNext());
			Vector3 const &pos = child->getInitialPosition();
			Quaternion const &rot = child->getInitialOrientation();
			loupEnt.push_back(SEntity(child->getName(), "ecriture_" + StringConverter::toString(index) + ".mesh"));
			loupNode.push_back(SNode(child->getName(), child->getName(), pos, rot));
			++index;
			if (index > 6)
			{
				index = 1;
			}
		}

		AddGeometries(loupEnt, loupNode);
	}
}

void CSceneEcriture :: Attach(void)
{
	CSceneBase::Attach();
	//m_pCurrentCamera->setPosition(-91.065f, -1907.565f, -55.884f);
	//Quaternion Quat(Radian(Math::PI/2.0f), Vector3(1, 0, 0));
	//m_pCurrentCamera->setOrientation(Quat);
	//m_OgreEngine.m_pViewPort->setBackgroundColour(ColourValue(1.0f, 1.0f, 1.0f, 1.0f));
}